package com.waijiaojun.tpo.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by Peter on 2018/3/1.
 */
public class Util {
    public static String toFullOssUrl(String url) {
        if (StringUtils.isBlank(url)) {
            return url;
        }
        if (url.startsWith("http://") || url.startsWith("https://")) {
            return url;
        }
        return Constants.ossDomain + url;
    }


    /**
     *
     * @param total 总题目数
     * @param correctNumber 答对的题目数
     * @return 3分制评分：小于0.6=1；0.6至1 =2 ；全对=3
     */
    public static Long calculatorScore(Long total,Long correctNumber){
        if(total==null || total==0){
            return 0L;
        }
        if(correctNumber==null || correctNumber==0){
            return 0L;
        }
        double c = correctNumber/(total*1.0);
        return getTrisection(c);
    }

    public static Long trisection(Double score) {
        if(score==null || score==0){
            return 0L;
        }
        return getTrisection(score);
    }

    private static Long getTrisection(Double score) {
        if(score<=0.6){
            return 1L;
        }else if(score<1){
            return 2L;
        }else{
            return 3L;
        }
    }
}
